#ifndef _HASH_T
#define _HASH_T

#include <cnix/list.h>

typedef int hashkey_t;

typedef struct hash_struct{
	list_t list;
}hash_t;

static inline void hash_init(hash_t * hash, int size)
{
	int i;

	for(i = 0; i < size; i++)
		list_head_init(&(hash[i].list));
}

static inline void hash_add(hash_t * hash, list_t * e, hashkey_t hashkey)
{
	list_add_head(&(hash[hashkey].list), e);
}

#define hash_find(hash, hashkey, comp, args...) \
({ \
	list_t * e; \
	hash_t * tmp = &hash[hashkey]; \
\
	e = &tmp->list; \
	do{ \
		e = e->next; \
		if(e == &(tmp->list)){ \
			e = NULL; \
			break; \
		} \
	}while(!comp(e, ##args)); \
\
	e; \
})

#endif
